package process
import (
	"fmt"
	"manyuser/common/message"
	"encoding/json"
	"manyuser/client/utils"
	"net"
)

type SmsProcess struct{

}
//群聊消息
func(this *SmsProcess)SendGroupMes(mes *message.Message)(err error){

	var smsMes message.SmsMes
	err=json.Unmarshal([]byte(mes.Data),&smsMes)
	if err!=nil{
		fmt.Println("err=json.Umarshal([]byte(mes.Data),&smsMes) wrong",err.Error())
		return
	}

	data,err:=json.Marshal(smsMes)
	if err!=nil{
		fmt.Println("json.Marshal(smsMes) wrong",err.Error())
		return
	}
	mes.Data=string(data)
	data,err=json.Marshal(mes)
	if err!=nil{
		fmt.Println("json.Marshal(mes) wrong",err.Error())
		return
	}

	for id,up:=range userMgr.onlineUsers{
		if id==smsMes.UserId{
			continue
		}
		this.SendMesToEachOnlineUser(data,up.Conn)
	}

	return
}

func (this *SmsProcess)SendMesToEachOnlineUser(data []byte,conn net.Conn){
	err:=(&utils.Transfer{Conn:conn,}).WritePkg(data)
	if err!=nil{
		fmt.Println("&utils.Transfer{Conn,CurUser.Conn,}.WritePkg(data) wrong",err.Error())
		return
	}
}